// 建造者模式 -用于对于复杂对象的创建
#include <iostream>
#include <string>
#include <memory>
using namespace std;
class Computer
{
public:
    void SetBoard(string Board)
    {
        _Board = Board;
    }
    void SetDispaly(string Display)
    {

        _Display = Display;
    }
    virtual  void SetOs()=0;
    void print()
    {
        cout << _Board << endl;
        cout << _Display << endl;
        cout << _OS << endl;
    }

protected:
    string _Board;
    string _Display;
    string _OS;
};

class Macbook : public Computer
{
public:
    void SetOs()
    {
        _OS = "Mac OS x12";
    }
};

class Builder
{
public:
    virtual void BulidBoard(string Board) = 0;
    virtual void BulidDispaly(string Display) = 0;
    virtual void BulidOs() = 0;
    virtual shared_ptr<Computer> computer() = 0;
};
class MacbookBuilder : public Builder
{
public:
    MacbookBuilder() : _computer(make_shared<Macbook>()) {}
    void BulidBoard(string Board) override
    {
        _computer->SetBoard(Board);
    }
    void BulidDispaly(string Board) override
    {
        _computer->SetDispaly(Board);
    }
    void BulidOs() override
    {
        _computer->SetOs();
    }
    shared_ptr<Computer> computer()
    {
        return _computer;
    }

private:
    shared_ptr<Computer> _computer;
};
class Director
{
public:
    Director(shared_ptr<Builder> builder)
        : _builder(builder)
    {
    }
    void create(const string& board, const string& Display)
    {
        _builder->BulidBoard(board);
        _builder->BulidDispaly(Display);
        _builder->BulidOs();
    }

private:
    shared_ptr<Builder> _builder;
};
int main()
{
    shared_ptr<Builder> b = make_shared<MacbookBuilder>(); // 先创建一个用于建造的模块，这个模块里面有要建造的对象
    shared_ptr<Director> d = make_shared<Director>(b);     // 指挥者主要是设置建造着各个模块的建造顺序
    d->create("华硕主板", "三星显示器");
    // 然后到这里已经初始化好了b里面的对象
    b->computer()->print();
}